package SG3D

import (
	. "SGEngine"
	"github.com/gl"
)

type Cube struct {
	Node
	VBuffer  *gl.Buffer
	TBuffer  *gl.Buffer
	MProgram *Program
	MColor   Color4
	Mat      *Material
}

func NewCube(X, Y, Z float64, Mat *Material) *Cube {
	RCube := new(Cube)
	RCube.Node = DefaultNode()
	RCube.NodeRender = RCube
	RCube.SetSize(X, Y, Z)
	RCube.MProgram = ACProgramMgr.GetProgram(PROGRAM_QUAD)
	V := ACBufferMgr.GetVertexBuffer(BUFFER_Cube)
	T := ACBufferMgr.GetTexBuffer(BUFFER_Cube)
	RCube.VBuffer = &V
	RCube.TBuffer = &T
	RCube.Mat = Mat
	return RCube
}

func (c *Cube) Render() {
	gl.Enable(gl.ALPHA_TEST)
	gl.AlphaFunc(gl.GREATER, 0)
	if c.Mat != nil {
		c.Mat.Use(c.VBuffer, c.TBuffer)
	}
	gl.DrawArrays(gl.TRIANGLES, 0, 36)
	c.VBuffer.Unbind(gl.ARRAY_BUFFER)
	c.TBuffer.Unbind(gl.ARRAY_BUFFER)
}
